package com.dchh.android.suverynew.act;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.dchh.android.suverynew.R;
import com.dchh.android.suverynew.adapter.MenuListAdapter;
import com.dchh.android.suverynew.base.SBaseActivity;
import com.dchh.android.suverynew.presenter.IUserCenterPresenter;
import com.dchh.android.suverynew.presenter.impl.UserCenterPresenter;
import com.dchh.android.suverynew.view.IUserCenterView;
import com.dhcc.android.base.utils.Constants;
import com.dhcc.android.base.utils.StringUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 个人中心
 *
 * @author zhoudan
 * @date 2015年5月19日
 */
public class UserCenterActivity extends SBaseActivity implements IUserCenterView {

    private LinearLayout view;
    private LinearLayout top;
    private TextView username;
    private ListView listview;
    private List<Class<?>> clsList = new ArrayList<Class<?>>();
    private MenuListAdapter adapter;

    private IUserCenterPresenter mUserPresneter = new UserCenterPresenter(this);

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_center);
    }

    @Override
    protected void setTitle(TextView toolbar_title) {
        toolbar_title.setText("个人中心");
    }

    @Override
    public void initView() {
        top = (LinearLayout) view.findViewById(R.id.user_top_layout);
        LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, Constants.screenHight / 3);
        top.setLayoutParams(p);

        username = (TextView) view.findViewById(R.id.username);
        username.setText(Constants.USERNAME);

        listview = (ListView) view.findViewById(R.id.nav_listview);

        listview.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (StringUtil.isFastDoubleClick(500)) {
                    return;
                }
                Intent intent = new Intent();
                intent.setClass(UserCenterActivity.this, clsList.get(position));
                startActivity(intent);

            }
        });
        mUserPresneter.initData(clsList);
    }

    @Override
    public void onInitDataSuccess(List<Map<String, String>> data) {
        if (adapter == null) {
            adapter = new MenuListAdapter(this, data);
        }
        listview.setAdapter(adapter);
    }
}
